* Nybom and Stuhler, Interpreting Trends in Intergenerational Mobility - Figure 2
* This file simulates five cases. In the manuscript, we show (in this order) cases 1, 2, 5 and 3. 


cd "/Users/janstuhler/Dropbox/MartinJanProjects/Trend_Project/Submissions/JPE/Final version/Simulations/Figure 2"
clear
set more off
   
* Input transition paths (computed in Excel file Figure2.xlsx)
input country period str18 periodlabel igc ige var_y sib 
* High returns, low inherit.
1 1 "T-2"   0.399	0.399	0.932	0.581
1 2 ""  	0.399	0.399	0.932	0.581
1 3 "T"     0.352	0.435	1.425	0.443
1 4 ""      0.392	0.399	1.470	0.463 
1 5 ""  	0.394	0.394	1.473	0.464
* Low returns, low inherit.                       
2 1 "T-2"   0.403	0.403	0.751	0.487  
2 2 ""  	0.403	0.403	0.751	0.487
2 3 "T"     0.366	0.403	0.911	0.341
2 4 ""      0.398	0.402	0.930	0.372
2 5 ""  	0.399	0.399	0.932	0.374 
* Low returns, high inherit.,                     
3 1 "T-2"   0.403	0.403	0.751	0.487  
3 2 ""  	0.403	0.403	0.751	0.487
3 3 "T"     0.366	0.403	0.911	0.341
3 4 ""      0.446	0.455	0.949	0.372
3 5 ""  	0.453	0.453	0.955	0.374 
* Low returns, high inherit., incr in market luck                       
4 1 "T-2"   0.403	0.403	0.751	0.487  
4 2 ""  	0.403	0.403	0.751	0.487
4 3 "T"     0.324	0.403	1.161	0.341
4 4 ""      0.392	0.400	1.209	0.372
4 5 ""  	0.399	0.399	1.215	0.374 
* High returns, high inherit.                      
5 1 "T-2"   0.453	0.453	0.955	0.487  
5 2 ""  	0.453	0.453	0.955	0.487
5 3 "T"     0.440	0.546	1.470	0.341
5 4 ""      0.519	0.533	1.555	0.372
5 5 ""  	0.524	0.524	1.566	0.374 
end


* Generate variance income in previous generation, and average of variance in current and previous generation
sort country period
by country: gen var_y_m1 = var_y[_n-1]
replace var_y_m1 = var_y if var_y_m1==.
by country: gen var_y_mix = (1/2)*(var_y+var_y[_n-1])
replace var_y_mix = var_y if var_y_mix==.

* Plot Great-Gatsby IGE-Variance(mixed), separate graphs
twoway  (connected ige var_y_mix if country==1 & period>1 , lwidth(thin) lpattern(solid) lcolor(black) msymbol(Oh) msize(med) `l1') ///
		(connected igc var_y_mix if country==1 & period>1 , lwidth(thin) lpattern(shortdash) lcolor(black) msymbol(X) msize(med) `l1') ///
		(line ige var_y_mix if country==1 & period>1 , lwidth(thin) lpattern(solid) lcolor(black)) ///
		, /*scheme(economist)*/ /*xlabel(none) yscale(range(0.35(0.05)0.45)) xscale(range(0.7(0.1)1.6)) ylabel(none) */	xsize(4) ysize(4)  ///
		xtitle("Income Variance") ytitle("Intergenerational Persistence") graphregion(color(white)) ///
		legend(lab(1 "Elasticity") lab(2 "Correlation") order(1 2) fcolor(white) size(med) bplacement(north) region(color(white))) ///
		yscale(axis(1)  lwidth(thin) lcolor(black)  titlegap(*5)) ///
		xscale(axis(1) lwidth(thin) lcolor(black)  titlegap(*5))   /// 
		/*text(0.451 0.76 "Country A" , box lcolor(ebackground) lwidth(none) bmargin(vlarge))*/ ///
		text(0.399 0.86 "Old SS" ,size(small)) ///
		text(0.44 1.1785 "T" ,size(small)) ///
		text(0.358 1.1785 "T" ,size(small)) ///
		text(0.394 1.54 "New SS" ,size(small)) ///
		text(0.403 1.4475 "T+1" ,size(small)) 
		graph export "Great_Gatsby_New_Times_C1.pdf" , replace fontface("Times-Roman") 
		
twoway  (connected ige var_y_mix if country==2 & period>1 , lwidth(thin) lpattern(solid) lcolor(black) msymbol(Oh) msize(med) `l1') ///
		(connected igc var_y_mix if country==2 & period>1 , lwidth(thin) lpattern(shortdash) lcolor(black) msymbol(X) msize(med) `l1') ///
		(line ige var_y_mix if country==2 & period>1 , lwidth(thin) lpattern(solid) lcolor(black)) ///
		, /*scheme(economist)*/ /* yscale(range(0.35(0.05)0.45)) xscale(range(0.7(0.1)1.6)) */	xsize(4) ysize(4)  ///
		xtitle("Income Variance") ytitle("Intergenerational Persistence") graphregion(color(white)) ///
		legend(lab(1 "Elasticity") lab(2 "Correlation") order(1 2) fcolor(white) size(med) bplacement(north) region(color(white))) ///
		yscale(axis(1)  lwidth(thin) lcolor(black)  titlegap(*5)) ///
		xscale(axis(1) lwidth(thin) lcolor(black)  titlegap(*5))   /// 
		/*text(0.451 0.76 "Country A" , box lcolor(ebackground) lwidth(none) bmargin(vlarge))*/ ///
		text(0.405 0.758 "Old SS" ,size(small)) ///
		text(0.405 0.831 "T" ,size(small)) ///
		text(0.368 0.831 "T" ,size(small)) ///
		text(0.399 0.95 "New SS" ,size(small)) ///
		text(0.404 0.918 "T+1" ,size(small)) 
		graph export "Great_Gatsby_New_Times_C2.pdf" , replace fontface("Times-Roman") 
		
twoway  (connected ige var_y_mix if country==3 & period>1 , lwidth(thin) lpattern(solid) lcolor(black) msymbol(Oh) msize(med) `l1') ///
		(connected igc var_y_mix if country==3 & period>1 , lwidth(thin) lpattern(shortdash) lcolor(black) msymbol(X) msize(med) `l1') ///
		(line ige var_y_mix if country==3 & period>1 , lwidth(thin) lpattern(solid) lcolor(black)) ///
		, /*scheme(economist)*/ /* yscale(range(0.35(0.05)0.45)) xscale(range(0.7(0.1)1.6)) */	xsize(4) ysize(4)  ///
		xtitle("Income Variance") ytitle("Intergenerational Persistence") graphregion(color(white)) ///
		legend(lab(1 "Elasticity") lab(2 "Correlation") order(1 2) fcolor(white) size(med) bplacement(north) region(color(white))) ///
		yscale(axis(1)  lwidth(thin) lcolor(black)  titlegap(*5)) ///
		xscale(axis(1) lwidth(thin) lcolor(black)  titlegap(*5))   /// 
		/*text(0.451 0.76 "Country A" , box lcolor(ebackground) lwidth(none) bmargin(vlarge))*/ ///
		text(0.407 0.758 "Old SS" ,size(small)) ///
		text(0.407 0.831 "T" ,size(small)) ///
		text(0.37 0.831 "T" ,size(small)) ///
		text(0.458 0.951 "New SS" ,size(small)) ///
		text(0.46 0.929 "T+1" ,size(small)) 
		graph export "Great_Gatsby_New_Times_C3.pdf" , replace fontface("Times-Roman") 
		
twoway  (connected ige var_y_mix if country==4 & period>1 , lwidth(thin) lpattern(solid) lcolor(black) msymbol(Oh) msize(med) `l1') ///
		(connected igc var_y_mix if country==4 & period>1 , lwidth(thin) lpattern(shortdash) lcolor(black) msymbol(X) msize(med) `l1') ///
		(line ige var_y_mix if country==4 & period>1 , lwidth(thin) lpattern(solid) lcolor(black)) ///
		, /*scheme(economist)*/ /* yscale(range(0.35(0.05)0.45)) */xscale(range(0.7(0.1)1.27))	xsize(4) ysize(4)  ///
		xtitle("Income Variance") ytitle("Intergenerational Persistence") graphregion(color(white)) ///
		legend(lab(1 "Elasticity") lab(2 "Correlation") order(1 2) fcolor(white) size(med) bplacement(north) region(color(white))) ///
		yscale(axis(1)  lwidth(thin) lcolor(black)  titlegap(*5)) ///
		xscale(axis(1) lwidth(thin) lcolor(black)  titlegap(*5))   /// 
		/*text(0.451 0.76 "Country A" , box lcolor(ebackground) lwidth(none) bmargin(vlarge))*/ ///
		text(0.407 0.758 "Old SS" ,size(small)) ///
		text(0.407 0.955 "T" ,size(small)) ///
		text(0.32 0.955 "T" ,size(small)) ///
		text(0.402 1.22 "New SS" ,size(small)) ///
		text(0.404 1.18 "T+1" ,size(small)) 
		graph export "Great_Gatsby_New_Times_C4.pdf" , replace fontface("Times-Roman") 
		
twoway  (connected ige var_y_mix if country==5 & period>1 , lwidth(thin) lpattern(solid) lcolor(black) msymbol(Oh) msize(med) `l1') ///
		(connected igc var_y_mix if country==5 & period>1 , lwidth(thin) lpattern(shortdash) lcolor(black) msymbol(X) msize(med) `l1') ///
		(line ige var_y_mix if country==5 & period>1 , lwidth(thin) lpattern(solid) lcolor(black)) ///
		, /*scheme(economist)*/ /* yscale(range(0.35(0.05)0.45)) */xscale(range(0.85(0.1)1.7))	xsize(4) ysize(4)  ///
		xtitle("Income Variance") ytitle("Intergenerational Persistence") graphregion(color(white)) ///
		legend(lab(1 "Elasticity") lab(2 "Correlation") order(1 2) fcolor(white) size(med) bplacement(north) region(color(white))) ///
		yscale(axis(1)  lwidth(thin) lcolor(black)  titlegap(*5)) ///
		xscale(axis(1) lwidth(thin) lcolor(black)  titlegap(*5))   /// 
		/*text(0.451 0.76 "Country A" , box lcolor(ebackground) lwidth(none) bmargin(vlarge))*/ ///
		text(0.453 0.89 "Old SS" ,size(small)) ///
		text(0.440 1.25 "T" ,size(small)) ///
		text(0.546 1.17 "T" ,size(small)) ///
		text(0.524 1.63 "New SS" ,size(small)) ///
		text(0.526 1.51 "T+1" ,size(small)) 
		graph export "Great_Gatsby_New_Times_C5.pdf" , replace fontface("Times-Roman") 

exit








